<?php

namespace backend\modules\home\models;

use Yii;

/**
 * This is the model class for table "mh_taglist".
 *
 * @property int $id
 * @property string $cont
 * @property int $create_at
 */
class Taglist extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mh_taglist';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['create_at'], 'integer'],
            [['cont'], 'string', 'max' => 20],
            ['cont', 'unique', 'targetClass' => self::className(), 'message' => '标签已存在！！'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cont' => '内容',
            'create_at' => '创建时间',
        ];
    }

    public function beforeSave($insert)
    {
        if(parent::beforeSave($insert)){
            if($this->isNewRecord){
                $this->create_at = time();
            }
            return true;
        }
        return false;
    }
}
